// 模拟后端动态生成路由
import { defineMock } from 'vite-plugin-mock-dev-server'

/**
 * roles：页面级别权限，这里模拟二种 "admin"、"common"
 * admin：管理员角色
 * common：普通角色
 */
const permissionRouter = [
  {
    path: '/permission/page',
    component: '/permission/page/index',
    name: 'PermissionPage',
    meta: {
      title: '页面权限',
      roles: ['admin', 'common']
    }
  },
  {
    path: '/permission/button',
    meta: {
      title: '按钮权限',
      roles: ['admin', 'common']
    },
    children: [
      {
        path: '/permission/button/router',
        component: 'permission/button/index',
        name: 'PermissionButtonRouter',
        meta: {
          title: '路由返回按钮权限',
          auths: ['permission:btn:add', 'permission:btn:edit', 'permission:btn:delete']
        }
      }
    ]
  },
  {
    path: '/order',
    component: '/order/index',
    name: 'Order',
    meta: {
      title: '订单管理',
      icon: 'i-tabler:lollipop',
      rank: 2
    }
  },

  {
    path: '/finance/withdraw',
    component: 'finance/withdraw',
    name: 'FinanceDraw',
    meta: {
      title: '状态统计',
      icon: 'i-tabler:lollipop',
      rank: 9
    }
  },
  {
    path: '/finance',
    meta: {
      title: '财务管理',
      icon: 'i-tabler:lollipop',
      rank: 3
    },
    children: [
      {
        path: '/bill',
        component: 'finance/bill/index',
        name: 'FinanceBill',
        meta: {
          title: '财务统计',
          icon: 'i-tabler:lollipop',
          rank: 7
        }
      },
      {
        path: '/account',
        component: 'finance/account',
        name: 'FinanceAccount',
        meta: {
          title: '财务账号',
          icon: 'i-tabler:lollipop',
          rank: 8
        }
      }
    ]
  },
  {
    path: '/form',
    component: 'form/index',
    name: 'Form',
    meta: {
      title: 'Schema表单'
    }
  }
]

export default defineMock({
  url: '/api/get-async-routes',
  method: 'GET',
  body: () => {
    return {
      success: true,
      data: permissionRouter
    }
  }
})
